﻿using System;
using System.Linq;
using System.Text;

using Xc.DataAccess.Core.Extensions;

namespace Xc.DataAccess.Core.Services
{
    /// <summary>
    /// 编码服务
    /// </summary>
    public class EncodingService : IEncodingService
    {
        /// <summary>
        /// 获取GB2312编码
        /// </summary>
        /// <returns></returns>
        public Encoding GetGB2312()
        {
            return GetEncoding("GB2312");
        }
        /// <summary>
        /// 获取指定编码
        /// </summary>
        /// <param name="encoding"></param>
        /// <returns></returns>
        public Encoding GetEncoding(string encoding)
        {
            var en = CodePagesEncodingProvider.Instance.GetEncoding(encoding);
            if (en == null)
            {
                return Encoding.GetEncoding(encoding);
            }
            else
            {
                return en;
            }
        }
        /// <summary>
        /// 获取指定编码方式
        /// </summary>
        /// <param name="encoding"></param>
        /// <returns></returns>
        public Encoding GetEncoding(int encoding)
        {
            var en = CodePagesEncodingProvider.Instance.GetEncoding(encoding);
            if (en == null)
            {
                return Encoding.GetEncoding(encoding);
            }
            else
            {
                return en;
            }
        }
    }
}
